package com.hospital.doctor.doctorc.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hospital.doctor.doctorc.entity.DrugEntity;
import com.hospital.doctor.doctorc.entity.MedicineEntity;
import com.hospital.doctor.doctorc.service.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName: MedicineController
 * @description：
 * @author：TanKai
 * @date：2021/9/17 17:43
 * @versions：v1.0
 */

@Controller
@RequestMapping("/doctorc")
public class MedicineController {

    @Autowired
    private MedicineService medicineService;

    //分页查询
    @RequestMapping("/selMedicine")
    public String selfy(Model model, Integer doctorId, String userName, String username, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageInfo<MedicineEntity> page = medicineService.MedicinePaging(doctorId, username, pageNum);
        model.addAttribute("page", page);
        model.addAttribute("doctorId", doctorId);
        model.addAttribute("userName", userName);
        model.addAttribute("username", username);
        return "doctor/MedicineSelect";
    }

    //删除
    @RequestMapping("/delete")
    public String del(Integer id) {
        Boolean delete = medicineService.delete(id);
        return JSON.toJSONString(delete);
    }

    //更新
    @RequestMapping("/update")
    @ResponseBody
    public String upd(Model model, MedicineEntity medicine) {
        boolean update = medicineService.update(medicine);
        return JSON.toJSONString(update);
    }

    //查询全部
    @RequestMapping("/selDrug")
    public String sellist(Model model) {
        List<DrugEntity> list = medicineService.list();
        model.addAttribute("list", list);
        return "doctor/MedicineSelect";
    }

    //验证旧密码
    @RequestMapping("/yanzenmima")
    public String mima(String doctorid, String doctorpwd, String doctorpwdxin, String doctorPwdOk_pwd) {
        boolean selectOK = medicineService.pwdSelectOK(doctorid, doctorpwd, doctorpwdxin, doctorPwdOk_pwd);
        return JSON.toJSONString(selectOK);
    }

}
